package com.umgsai.thread.thread22;

public class RunThread extends Thread {
	volatile private boolean isRunning = true;
    public boolean isRunning() {
        return isRunning;
    }
    public void setRunning(boolean isRunning) {
        this.isRunning = isRunning;
    }
    
    @Override
    public void run() {
        System.out.println("进入run方法...");
        while (isRunning) {
            System.out.println("running....");
            try {
                Thread.sleep(500);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("线程被停止...");
    }
    
    public static void main(String[] args) {
        try {
            RunThread runThread = new RunThread();
            runThread.start();
            Thread.sleep(1000);
            runThread.setRunning(false);
            System.out.println("已将isRunning设置为false");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
